package com.yitongmao.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yitongmao.bean.ClassfyLeftBean;
import com.yitongmao.yitmfruit.R;

import java.util.List;

import static com.yitongmao.util.UIUtils.getResources;

/*
* 作者：梁伟航 on 2017/7/16 15:48
* 类的用途：
*/
public class ClassfitListViewAdapter extends BaseAdapter {
    private Context context;
    private int num;
    private List<ClassfyLeftBean.GetClassNameListBean> getClassNameList;

    public ClassfitListViewAdapter(Context context, List<ClassfyLeftBean.GetClassNameListBean> getClassNameList) {
        this.context = context;
        this.getClassNameList=getClassNameList;
    }
    public void changeSelected(int positon){ //刷新方法
        if(positon != num){
            num = positon;
           notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return getClassNameList.size();
    }

    @Override
    public Object getItem(int position) {
        return getClassNameList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.classfitlistviewitem, null);
            viewHolder.mTextView = (TextView) convertView.findViewById(R.id.mTextView);
            convertView.setTag(viewHolder);//绑定ViewHolder对象
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.mTextView.setText(getClassNameList.get(position).name);
        Drawable nav_up=getResources().getDrawable(R.drawable.s);
        nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
        if (num==position){
            //点击的时候赋值
            convertView.setBackgroundResource(R.color.sko);
            viewHolder.mTextView.setCompoundDrawables(nav_up, null, null, null);
        }else {
            convertView.setBackgroundResource(R.color.white);
            viewHolder.mTextView.setCompoundDrawables(null, null, null, null);
        }

        return convertView;
    }

   static class ViewHolder {
        public TextView mTextView;
    }
}
